/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-01-04
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-04-16
 * @Description: 布局容器
 */
import 'package:flutter/material.dart';
//
import 'package:chat_client/widgets/custom_global_widgets.dart';
// 页面
import '../mobile/individual/individual_screen.dart';

class WebHomeScreen extends StatefulWidget {
  const WebHomeScreen({super.key});

  @override
  State<StatefulWidget> createState() {
    return _WebHomeScreenState();
  }
}

// 私有
class _WebHomeScreenState extends State<WebHomeScreen> {
  // 存储每个按钮的选中状态
  int _currentIndex = 0;

  //
  final List<Widget> _pages = [
    const IndividualScreen(), // 个人资料页面
    const IndividualScreen(), // 个人资料页面
    const IndividualScreen(), // 个人资料页面
  ];

  // 控制页面切换的PageController
  final PageController _pageController = PageController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: BoxDecoration(),
        child: Center(
            child: Container(
          width: 980,
          height: 640,
          padding: EdgeInsets.all(10),
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [
                Color(0XFFFFF4FF),
                Color(0XFFD9EBFF),
              ], // 渐变颜色
              begin: Alignment.topLeft, // 渐变起点
              end: Alignment.bottomRight, // 渐变终点
            ),
            boxShadow: [
              BoxShadow(color: Color(0xFFEDEDED), offset: Offset(2, 4))
            ],
            borderRadius: BorderRadius.circular(10),
          ),
          child: Row(
            children: [
              Column(
                children: [
                  //
                  Text(
                    'chat_client',
                    style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                  ),
                  SizedBox(height: 20),
                  //
                  SquareAvatar(
                    size: 40,
                    borderRadius: 40,
                  ),
                  SizedBox(height: 20),
                  _buildIconButton(
                      index: 0,
                      icon: Icons.sms,
                      onTap: () {
                        setState(() {
                          _currentIndex = 0;
                        });
                      }),
                  SizedBox(height: 10),
                  _buildIconButton(
                      index: 1,
                      icon: Icons.group,
                      onTap: () {
                        setState(() {
                          _currentIndex = 1;
                        });
                      }),
                  SizedBox(height: 10),
                  _buildIconButton(
                      index: 2,
                      icon: Icons.explore,
                      onTap: () {
                        setState(() {
                          _currentIndex = 2;
                        });
                      }),
                  Spacer(),
                  _buildIconButton(
                      index: 3, icon: Icons.settings, onTap: () {}),
                ],
              ),
              Container(
                padding: EdgeInsets.all(20),
                decoration: BoxDecoration(),
                width: _currentIndex == 0 ? 500 : 300,
                child: PageView(
                  controller: _pageController,
                  onPageChanged: (index) {
                    setState(() {
                      _currentIndex = index;
                    });
                  },
                  children: _pages,
                ),
              ),
              Expanded(
                child: Container(
                  decoration: BoxDecoration(),
                  // child:
                ),
              )
            ],
          ),
        )),
      ),
    );
  }

  // // 构建按钮
  _buildIconButton(
      {required int index,
      required IconData icon,
      required VoidCallback onTap}) {
    return IconButton(
      onPressed: onTap,
      icon: Icon(
        icon,
        color: Color.fromARGB(255, 66, 69, 70),
        size: 26,
      ),
      hoverColor: Color.fromARGB(255, 206, 204, 204).withValues(alpha: 0.2),
      isSelected: _currentIndex == index,
      mouseCursor: MouseCursor.defer,
      selectedIcon: Icon(
        icon,
        color: Color.fromARGB(255, 90, 140, 255),
        size: 26,
      ),
      style: ButtonStyle(
        backgroundColor: WidgetStateProperty.all(
          _currentIndex == index
              ? Color.fromARGB(255, 206, 204, 204).withValues(alpha: 0.2)
              : Colors.transparent, // 背景颜色
        ),
        // 设置阴影的形状
        elevation: WidgetStateProperty.all(4), // 设置阴影的高度
        shape: WidgetStateProperty.all(RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(10), // 设置圆角正方形
        )),
      ),
    );
  }
}
